﻿<cfsilent>
	<cfsetting requesttimeout="90" />
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		
		termId = event.getArg("TermID", event.getArg("TID"));
		
		/* 学籍相关信息 */
		studentId = sessionAdvice.getAutherUserID();
		
		passArgs = structNew();
		structInsert( passArgs, "TID", termId, true);
		structInsert( passArgs, "STU", studentId, true);
		structInsert( passArgs, "TabID", "labChoosenType", true);

		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		
		chooseProp = getProperty("serviceFactory").getBean("choosePropertyAdvice");

		choosenArray = [];
		
		preCharged = 0;
		payCharged = 0;
		paySecondCharged = 0;
		payAssistCharged = 0;
		
		chargeArray = [];
		
		chargePerCredit = 0;
		chargeRetakenPerCredit = 0;
		chargeSecondaryPerCredit = 0;
		chargeAssistPerCredit = 0;
		
		if ( len(studentId) and len(termId) ) {
			
			/* 正常专业学费 */
			sql = "	SELECT
						tc.regular,tc.resit
					FROM
						t_charge tc
					WHERE
						EXISTS(
							 SELECT
								 stu.stu_id
							 FROM
								 t_student stu
								 INNER JOIN t_class clz ON clz.cls_id = stu.cls_id
							 WHERE
								 tc.grade = clz.grade
								 AND
								 tc.sbj_id = clz.sbj_id
								 AND
								 stu.stu_id = :studentId 
						)";
			
			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name="studentId", value=studentId, cfsqltype="cf_sql_varchar");
			rs_charge = queryObj.execute(sql=sql).getResult();

			if(rs_charge.recordCount GT 0){
				chargePerCredit = rs_charge['regular'][1];
				chargeRetakenPerCredit = rs_charge['resit'][1];
			}
			
			/* 辅修专业学费 */
			sql = "	SELECT
						tc.assist
					FROM
						t_charge tc
					WHERE
						EXISTS(
							 SELECT 
								 tss.stusec_id
							 FROM
								 t_student_secsubject tss
							 WHERE
								 tc.sbj_id = tss.sbj_id
								 AND
								 tc.grade = tss.grade
								 AND
								 tss.stu_id = :studentId 
						)";
			
			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name="studentId", value=studentId, cfsqltype="cf_sql_varchar");
			rs_assist = queryObj.execute(sql=sql).getResult();

			if(rs_assist.recordCount GT 0){
				chargeAssistPerCredit = rs_assist['assist'][1];
			}
			
			/* 双学位专业学费 */
			sql = "	SELECT
						tc.secondary
					FROM
						t_charge tc
					WHERE
						EXISTS(
							 SELECT
							 	 tss.stusec_id
							 FROM
								 t_student_secdegree tss
							 WHERE
								 tc.grade = tss.grade
								 AND
								 tc.sbj_id = tss.sbj_id
								 AND
								 tss.stu_id = :studentId 
						)";
			
			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name="studentId", value=studentId, cfsqltype="cf_sql_varchar");
			rs_secondary = queryObj.execute(sql=sql).getResult();
			
			if( rs_secondary.recordCount ){
				chargeSecondaryPerCredit = rs_secondary['secondary'][1];
			}

			/* 读取学生的已选课程 */
			sql = "	SELECT
						sc.cid,c.course_name,c.course_credit,
						ct.turn,
						sc.task_type,sc.scc_id,sc.st,sc.retaking,
						sc.choose_time,sc.choose_prop,sc.task_id,
						sc.charge_time
					FROM
						t_student_course sc
						INNER JOIN t_course c ON sc.cid = c.cid
						INNER JOIN t_choose_turn ct ON ct.ct = sc.ct
					WHERE
						sc.stu_id = :studentId 
						AND
						sc.term_id = :termId 
					ORDER BY
						sc.retaking DESC,sc.st,sc.task_type,c.course_name";
			
			queryObj = new Query(datasource = application.dnsSlave);
			queryObj.addParam(name="studentId", value=studentId, cfsqltype="cf_sql_varchar");
			queryObj.addParam(name="termId", value=termId, cfsqltype="cf_sql_char");
			rs_choosen = queryObj.execute(sql=sql).getResult();
			
		}
		
	</cfscript>
</cfsilent>

<cfif rs_choosen.recordCount >
	<table class="UIEditable">
		<thead>
			<tr>
				<td width="18"></td>
				<td>教学班</td>
				<!---<td>任课教师</td>--->
				<td>学分</td>
				<td>开课类别</td>
				<td>修读方式</td>
				<td>重修</td>
				<td>学费</td>
				<td>结算时间</td>
				<td width="18"></td>
			</tr>
		</thead>
		<tbody>
			<cfset row = 0 />
            <cfloop query="rs_choosen">
				<cfset row++ />
				
				<cfset structInsert( passArgs, "SCC", rs_choosen.scc_id, true) />
				
				<cfset taskArray = [] />
				
				<!--- 读取教学任务教师和任务性质 --->
				<cfswitch expression="#rs_choosen.task_type#">
					<cfcase value="P">
                        <cfset sql = "	SELECT
											tch.tch_name,tc.campus_name,tsk.task_week
										FROM
											t_task tsk
											INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
											INNER JOIN t_campus tc ON tc.campus_id = tsk.campus_id
										WHERE
											tsk.tsk_id = :taskId " />
						<cfset queryObj = new Query(datasource = application.dnsSlave)/>
                        <cfset queryObj.addParam(name="taskId", value=rs_choosen.task_id, cfsqltype="cf_sql_varchar")/>
                        <cfset rs_task = queryObj.execute(sql=sql).getResult()/>
					</cfcase>
					<cfcase value="C">
                        <cfset sql = "	SELECT
											tch.tch_name,tc.campus_name,tsk.task_week
										FROM
											t_common_task tsk
											INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
											INNER JOIN t_campus tc ON tc.campus_id = tsk.campus_id
										WHERE
											tsk.tsk_id = :taskId " />
						<cfset queryObj = new Query(datasource = application.dnsSlave)/>
                        <cfset queryObj.addParam(name="taskId", value=rs_choosen.task_id, cfsqltype="cf_sql_varchar")/>
                        <cfset rs_task = queryObj.execute(sql=sql).getResult()/>
					</cfcase>
					<cfcase value="R">
						<cfset sql = "	SELECT
											tch.tch_name,tc.campus_name,tsk.task_week
										FROM
											t_reopen_task tsk
											INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
											INNER JOIN t_campus tc ON tc.campus_id = tsk.campus_id
										WHERE
											tsk.tsk_id = :taskId " />
						<cfset queryObj = new Query(datasource = application.dnsSlave)/>
                        <cfset queryObj.addParam(name="taskId", value=rs_choosen.task_id, cfsqltype="cf_sql_varchar")/>
                        <cfset rs_task = queryObj.execute(sql=sql).getResult()/>
					</cfcase>
					<cfcase value="T">
						<cfset sql = "	SELECT
											tch.tch_name,tc.campus_name,tsk.task_week
										FROM
											t_sport_task tsk
											INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
											INNER JOIN t_campus tc ON tc.campus_id = tsk.campus_id
										WHERE
											tsk.tsk_id = :taskId " />
						<cfset queryObj = new Query(datasource = application.dnsSlave)/>
                        <cfset queryObj.addParam(name="taskId", value=rs_choosen.task_id, cfsqltype="cf_sql_varchar")/>
                        <cfset rs_task = queryObj.execute(sql=sql).getResult()/>
					</cfcase>
				</cfswitch>
				
               	<cfif rs_task.recordCount>
					<!--- 如果教学任务有效 --->
					<cfset chooseProp.parseProperty( rs_choosen.choose_prop ) />
					<tr class="editRows <cfif rs_choosen.st eq "R">noticeRow1</cfif> <cfif rs_choosen.st eq "F">noticeRow2</cfif>">
						<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
						<td><cfoutput>#rs_choosen.course_name#</cfoutput></td>
						<!---<td><cfoutput>#rs_task.tch_name#</cfoutput></td>--->
						<td><span class="numeric"><cfoutput>#numberFormat(rs_choosen.course_credit, '_.__')#</cfoutput></span></td>
						<td><cfoutput>#dictAdvice.getTaskType( rs_choosen.task_type )#</cfoutput></td>
						<td><cfoutput>#dictAdvice.getStudyType( rs_choosen.st )#</cfoutput></td>
						<td><cfif rs_choosen.retaking eq "1">是</cfif></td>
						
						<td>
							<cfset thisCharge = 0 />
							<cfswitch expression="#rs_choosen.st#">
								<cfcase value="N,F,E">
									<!--- 正常 或 补修 --->
									<cfset thisCharge = chargePerCredit*rs_choosen.course_credit />
									<cfset preCharged = preCharged + thisCharge />
									<span class="numeric bold"><cfoutput>#numberFormat(thisCharge, "_.__")#</cfoutput></span>
								</cfcase>
								<cfcase value="R">
									<!--- 重修 --->
									<cfset thisCharge = chargeRetakenPerCredit*rs_choosen.course_credit />
									<cfset payCharged = payCharged + thisCharge />
									<span class="numeric bold"><cfoutput>#numberFormat(chargeRetakenPerCredit*rs_choosen.course_credit, "_.__")#</cfoutput></span>
								</cfcase>
								<cfcase value="S">
									<!--- 双学位 --->
									<cfset thisCharge = chargeSecondaryPerCredit*rs_choosen.course_credit />
									<cfset paySecondCharged = paySecondCharged + thisCharge />
									<span class="numeric bold"><cfoutput>#numberFormat(chargeSecondaryPerCredit*rs_choosen.course_credit, "_.__")#</cfoutput></span>
								</cfcase>
								<cfcase value="A">				
									<!--- 辅修 --->
									<cfset thisCharge = chargeAssistPerCredit*rs_choosen.course_credit />
									<cfset payAssistCharged = payAssistCharged + thisCharge />
									<span class="numeric bold"><cfoutput>#numberFormat(chargeAssistPerCredit*rs_choosen.course_credit, "_.__")#</cfoutput></span>
								</cfcase>
							</cfswitch>
						</td>
						
						<td>
							<cfif rs_choosen.choose_time neq rs_choosen.charge_time>
								<span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString(rs_choosen.charge_time, 'YYYY/MM/DD')#</cfoutput></span>
							</cfif>
						</td>
						
						<td>
							<cfif chooseProp.getPrePaid()>
									<span title="从预交学费中扣除" class="stat charged"></span>
								<cfelseif chooseProp.getPaid()>
									<span title="已结算" class="stat checked"></span>
								<cfelse>
									<span title="未结算" class="stat settime"></span>
							</cfif>
						</td>
					</tr>
					<!--- javascript:removeTask(chooserId, courseId, stuId, termId, taskType, taskId); --->
					<cfelse>
					<!--- 如果教学任务无效 则直接删除错误的选课记录 --->
				</cfif>
			</cfloop>
		</tbody>	
	</table>
	
	<cfset colspan = 4 />
	<cfif payCharged gt 0><cfset colspan += 2 /></cfif>
	<cfif paySecondCharged gt 0><cfset colspan += 2 /></cfif>
	<cfif payAssistCharged gt 0><cfset colspan += 2 /></cfif>
	
	<table class="UIEditable">
		<tbody>	
			<tr class="breakRowsBold">
				<td colspan="<cfoutput>#colspan#</cfoutput>"></td>
			</tr>
			<tr>
				<td width="18"></td>
				<td>合计: <span class="numeric"><cfoutput>#arrayLen(choosenArray)#</cfoutput></span> 门课程</td>
				<td align="center" width="40">预收</td>
				<td align="center" width="80"><span class="numeric bold"><cfoutput>#numberFormat(preCharged, "_.__")#</cfoutput></span></td>
				<cfif payCharged gt 0>
					<td align="center" width="80">重新学习</td>
					<td align="center" width="80"><span class="numeric bold"><cfoutput>#numberFormat(payCharged, "_.__")#</cfoutput></span></td>
				</cfif>
				<cfif paySecondCharged gt 0>
					<td align="center" width="60">双学位</td>
					<td align="center" width="80"><span class="numeric bold"><cfoutput>#numberFormat(paySecondCharged, "_.__")#</cfoutput></span></td>
				</cfif>
				<cfif payAssistCharged gt 0>
					<td align="center" width="40">辅修</td>
					<td align="center" width="80"><span class="numeric bold"><cfoutput>#numberFormat(payAssistCharged, "_.__")#</cfoutput></span></td>
				</cfif>
			</tr>
		</tbody>
	</table>
	
	
	<cfelse>
	<div class="systemNotice">
		<h3>学生没有选课</h3>
	</div>
</cfif>